package com.wwj.study.template.dao;

import com.wwj.study.template.JdbcTemplate;
import com.wwj.study.template.RowMapper;
import com.wwj.study.template.entity.MemberEntity;

import java.lang.reflect.Member;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by lenovo on 2018/11/18.
 */
public class MemberDao {

    //为什么不继承，主要是为了解耦
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(null);


    public List<?> query(){
        String sql = "select * from t_member";
        //传入sql语句
        return jdbcTemplate.executeQuery(sql, new RowMapper<MemberEntity>() {
            //返回结果集转实体对象
            @Override
            public MemberEntity mapRow(ResultSet rs, int i) throws SQLException {
                MemberEntity e=new MemberEntity();
                e.setId(rs.getInt("id"));
                e.setName(rs.getString("name").toString());
                return e;
            }
        },null);
    }

}
